package com.example.demo.dao;

import com.example.demo.entity.Person;
import com.example.demo.entity.dto.UserDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

@Repository
public interface PersonRepository extends JpaRepository<Person, Long> {

//    Optional<Person> findByName(String name);

//    @Async
//    Future<Person> findByName(String name);

    @Async
    CompletableFuture<Person> findByName(String name);

    List<Person> findByAgeGreaterThan(int age);

    @Query("select p from Person p where p.name = :name")
    Optional<Person> findByNameCustomQuery(@Param("name") String name);

    @Query("select p.name from Person p where p.id = :id")
    String findPersonNameById(@Param("id") Long id);

    @Modifying
    @Query("update Person p set p.name = ?1 where p.id = ?2")
    Integer updatePersonNameById(String name,Long id);

}
